
  <template>
  <!-- 参数设置 -->
  <div class="bf-commont-template padding-t">
    <el-tabs :tab-position="'left'" v-model="activeName" @tab-click="handleClick" class="margin-l margin-r">
      <el-tab-pane label="考勤设置" name="first">
        <div class="clearfix bf-top-button">
          <div class="float-l">
            <el-button type="primary" @click="showTypeAdd">新增考勤设置</el-button>
          </div>
          <div class="float-r">
            <div class="float-l">
              <el-input placeholder="请输入工作地址搜索内容" prefix-icon="el-icon-search" v-model="searchData1" @keyup.enter.native="quickSearch1">
              </el-input>
            </div>
            <div class="float-l padding-l">
              <!-- <el-button type="primary" @click="showSetSearch">高级筛选</el-button> -->
            </div>
          </div>
        </div>
        <bf-table :data="recruitTypeData" :setting="setListSetting" :rowAction="rowAction1" @editSubmit="setEditSubmit" @pageChange="pageChange" ref="table1"></bf-table>
      </el-tab-pane>
      <el-tab-pane label="考勤规则" name="second">
        <div class="clearfix bf-top-button">
          <div class="float-l">
            <el-button type="primary" @click="showInterviewAdd">新增考勤规则</el-button>
          </div>
          <div class="float-r">
            <div class="float-l">
              <el-input placeholder="请输入规则名称搜索内容" prefix-icon="el-icon-search" v-model="searchData2" @keyup.enter.native="quickSearch2">
              </el-input>
            </div>
            <div class="float-l padding-l">
              <!-- <el-button type="primary" @click="showRuleSearch">高级筛选</el-button> -->
            </div>
          </div>
        </div>
        <bf-table :data="interviewProblemData" :setting="ruleListSetting" :rowAction="rowAction2" @editSubmit="ruleEditSubmit" @pageChange="pageChange" ref="table2"></bf-table>
      </el-tab-pane>

    </el-tabs>

    <!--高级搜索 -->
    <bf-table-search :editForm='setListSetting' :title="'高级搜索'" ref='searchSetrRef' @formSubmit='searchSetSubmit'></bf-table-search>
    <!--高级搜索 -->
    <bf-table-search :editForm='ruleListSetting' :title="'高级搜索'" ref='searchRulerRef' @formSubmit='searchRuleSubmit'></bf-table-search>

    <!-- 添加设置 -->
    <bf-table-add  :title="'新增考勤设置'" :editForm='setListSetting' ref='setRef' @formSubmit='addSetSubmit' :editRules="setRules"></bf-table-add>
    <!--编辑设置 -->
    <bf-table-edit :editForm='setEditSetting' ref='editsetRef' @formSubmit='editSetSubmit' :editRules="setRules"></bf-table-edit>
    <!-- 添加规则 -->
    <bf-table-add :editForm='ruleListSetting' ref='ruleRef' @formSubmit='addRuleSubmit' :editRules="ruleRules"></bf-table-add>
    <!-- 编辑规则-->
    <bf-table-edit :editForm='ruleListSetting' ref='editruleRef' @formSubmit='editRuleSubmit' :editRules="ruleRules"></bf-table-edit>
  </div>
</template>

<script>
/** @
 * addRuleChannel,新增渠道
 * addRuleQuestion,新增题库
 * addRuleEliminate ,新增淘汰原因
 */
import { getSetlist, getruleList, editSet, addSet, editRuleSub, addRule, deleteSet, deleteRule } from './api.js'
import {
  setListSetting,
  ruleListSetting,
  setEditSetting
} from './table.setting.js'

export default {
  data() {
    return {
      searchData1: '',
      searchData2: '',
      activeName: 'first',
      recruitTypeData: {},
      interviewProblemData: {},
      obsoleteData: {},
      setListSetting: setListSetting,
      ruleListSetting: ruleListSetting,
      setEditSetting: setEditSetting,
      userData: {
      },
      rowAction1: [
        {
          label: '查看',
          click: (item) => {
            this.$refs.table1.showDetail(item)
          }
        },
        {
          label: '编辑',
          click: (item) => {
            this.$refs.editsetRef.show(item.scope)
          }
        },
        {
          label: '删除',
          click: (item) => {
            this.$refs.table1.showDelete(item)
          }
        }
      ],
      rowAction2: [
        {
          label: '查看',
          click: (item) => {
            this.$refs.table2.showDetail(item)
          }
        },
        {
          label: '编辑',
          click: (item) => {
            this.$refs.editruleRef.show(item.scope)
          }
        },
        {
          label: '删除',
          click: (item) => {
            this.$refs.table2.showDelete(item)
          }
        }
      ],


      setRules: {
        addr: [
          { required: true, message: '请选择工作地址', trigger: 'blur' }
        ],

        ruleId: [
          { required: true, message: '请选择规则', trigger: 'blur' }
        ]

      },
      ruleRules: {
        ruleName: [
          { required: true, message: '请输入名称', trigger: 'blur' },
          { min: 2, max: 20, message: '长度在 2 到 20个字符', trigger: 'blur' }
        ],
        attendRule: [
          { required: true, message: '请选择考勤规则', trigger: 'blur' }
        ],
        elasticFlag: [
          { required: true, message: '请选择是否弹性上班制', trigger: 'blur' }
        ],
        exemptTime: [
          { required: true, message: '请输入豁免时间', trigger: 'blur' }
        ], abstmLimit: [
          { required: true, message: '请输入迟到早退时间', trigger: 'blur' }
        ],
        punchTime1: [
          { required: true, message: '请选择上班时间', trigger: 'blur' }
        ],
        punchTime2: [
          { required: true, message: '请选择下班时间', trigger: 'blur' }
        ],

        isValid: [
          { required: true, message: '请选择是否有效', trigger: 'blur' }
        ],
        restTime: [
          { required: true, message: '请输入 休息时长', trigger: 'blur' }
        ],
      },
      searchParams: { // 搜索条件
        page: 1
      }
    }
  },
  mounted: function() {
    this.searchList()
  },
  methods: {
    addSetSubmit(form) { // 新增设置
      addSet(form).then((response) => {
        if (response.success) {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.$refs.setRef.hiden()
          this.searchList()
        }
      })
    },
    addRuleSubmit(form) { // 新增规则
      addRule(form).then((response) => {
        if (response.success) {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.$refs.ruleRef.hiden()
          this.searchList()
        }
      })
    },
    editSetSubmit(form) { // 编辑保存地点设置
      editSet(form).then((response) => {
        if (response.success) {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.$refs.editsetRef.hiden()
          this.searchList()
        }
      })
    },
    editRuleSubmit(form) { // 编辑保存规则
      editRuleSub(form).then((response) => {
        if (response.success) {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.$refs.editruleRef.hiden()
          this.searchList()
        }
      })
    },
    setEditSubmit(params, formType, formList) { // 删除
      if (formType === 'delete') {
        deleteSet(params.row.id).then(response => {
          if (response.success) {
            this.$message({
              message: '删除成功!',
              type: 'success'
            })
            this.searchList()
          }
        })
      }
    },
    ruleEditSubmit(params, formType, formList) { // 删除
      if (formType === 'delete') {
        deleteRule(params.row.ruleId).then(response => {
          if (response.success) {
            this.$message({
              message: '删除成功!',
              type: 'success'
            })
            this.searchList()
          }
        })
      }
    },
    pageChange(pageObj) {
      this.searchParams.page = pageObj.page
      this.searchParams.pageSize = pageObj.pageSize
      this.searchList()
    },
    showSetSearch() {
      this.$refs.searchSetrRef.show()
    },
    showRuleSearch() {
      this.$refs.searchRulerRef.show()
    },
    searchSetSubmit(form) {
      this.getSetlist()
      this.$refs.searchSetrRef.hiden()
    },
    searchRuleSubmit(form) {
      this.getRulelist()
      this.$refs.searchRulerRef.hiden()
    },
    showTypeAdd() {
      this.activeName = 'first'
      this.$refs.setRef.show()
    },
    showInterviewAdd() {
      this.activeName = 'second'
      this.$refs.ruleRef.show()
    },
    quickSearch1() {
      this.searchParams = {
        page: 1,
        itemText: this.searchData1
      }
      this.searchList()
    },
    quickSearch2() {
      this.searchParams = {
        page: 1,
        ruleName: this.searchData2
      }
      this.searchList()
    },
    handleClick(tab, event) {
      this.searchParams.page = 1
      this.searchList()
    },
    searchList() {
      if (this.activeName === 'first') {
        getSetlist(this.searchParams).then(response => {
          this.recruitTypeData = response
        })
      }

      if (this.activeName === 'second') {
        getruleList(this.searchParams).then(response => {
          this.interviewProblemData = response
        })
      }
    }
  }
}
</script>

<style scoped>

</style>
